/* Copyright (C) 2003, Charles Wang.
 * Author:  Charles Wang <charles@linux.net.cn>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANT; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public LIcense for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#ifndef __UTILS_H__
#define __UTILS_H__

typedef struct {
    int  maxlevel;
    int  blkmask;
}   umnt_info;

struct stat;

char * probe_path(const char *path);
char * mount_path(const char *path, umnt_info *ui);
void   umount_path(const umnt_info *ui);

int lomount(const char *file, const char *mntdir, const char *fstype);
int loumount(const char *mntdir);

int exec_and_wait(char *argv[]);
int  do_modprobe(char *module);
int  do_modprobe2(char* argv[]);
void load_all_filesystem_modules(void);
int  check_kmodule_loaded(const char *module);
int  check_filesystem(const char *fstype);
const char *guess_load_fstype(const char *dev_file);

void         relist_clear(void);
void         relist_append(const char *result);
const char * relist_first(char **iter);
const char * relist_next(char **iter);

/* Possible drvtype are: block, char, ide, isdn, net, scsi, sound, usb.... */
int  check_drv(const char *module, const char *drvtype);

/* CAP is the capacity of D, N is 0 or the number of chars to copy. */
static inline char *xstrncpy(char *d, const char *s, int cap, int n)
{
    char *r;
    if (n <=0 || n > cap - 1)
        n = cap - 1;
    r = strncpy(d, s, n);
    d[n] = '\0';
    return r;
}

/* Walk down the tree of _dir, if walk_func return non-zero, the process will
   stop. Return 1 if process is stopped by walk_func, -1 if error occurs,
   otherwise return 0. */
int walk_tree(const char *_dir,
              int (*walk_func)(const char *_dirname,
                               const char *_basename, 
                               struct stat *_mode));
                               
#endif
